home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / regcode / regsampl.frm < prev    next >
Text File  |  1998-08-11  |  9KB  |  270 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "ECLIPSE Registry Demo"
  4.    ClientHeight    =   2685
  5.    ClientLeft      =   45
  6.    ClientTop       =   330
  7.    ClientWidth     =   5595
  8.    LinkTopic       =   "Form1"
  9.    LockControls    =   -1  'True
  10.    ScaleHeight     =   2685
  11.    ScaleWidth      =   5595
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.TextBox txtAppKeyName 
  14.       Height          =   288
  15.       Left            =   1375
  16.       TabIndex        =   9
  17.       Text            =   "Text1"
  18.       Top             =   100
  19.       Width           =   4140
  20.    End
  21.    Begin VB.CommandButton cmdExit 
  22.       Caption         =   "E&xit"
  23.       Height          =   320
  24.       Left            =   4320
  25.       TabIndex        =   8
  26.       Top             =   2275
  27.       Width           =   1200
  28.    End
  29.    Begin VB.Frame Frame1 
  30.       Height          =   1716
  31.       Left            =   96
  32.       TabIndex        =   1
  33.       Top             =   456
  34.       Width           =   5412
  35.       Begin VB.CommandButton cmdReg 
  36.          Caption         =   "Delete Key"
  37.          Height          =   320
  38.          Index           =   2
  39.          Left            =   4000
  40.          TabIndex        =   13
  41.          Top             =   900
  42.          Width           =   1200
  43.       End
  44.       Begin VB.CommandButton cmdReg 
  45.          Caption         =   "Delete Value"
  46.          Height          =   320
  47.          Index           =   3
  48.          Left            =   4000
  49.          TabIndex        =   12
  50.          Top             =   1250
  51.          Width           =   1200
  52.       End
  53.       Begin VB.OptionButton optRegType 
  54.          Caption         =   "SZ (string)"
  55.          Height          =   204
  56.          Index           =   1
  57.          Left            =   2200
  58.          TabIndex        =   11
  59.          Top             =   850
  60.          Value           =   -1  'True
  61.          Width           =   1605
  62.       End
  63.       Begin VB.OptionButton optRegType 
  64.          Caption         =   "DWORD (numbers)"
  65.          Height          =   204
  66.          Index           =   0
  67.          Left            =   100
  68.          TabIndex        =   10
  69.          Top             =   850
  70.          Width           =   2085
  71.       End
  72.       Begin VB.CommandButton cmdReg 
  73.          Caption         =   "Query Value"
  74.          Height          =   320
  75.          Index           =   1
  76.          Left            =   4000
  77.          TabIndex        =   7
  78.          Top             =   550
  79.          Width           =   1200
  80.       End
  81.       Begin VB.CommandButton cmdReg 
  82.          Caption         =   "Store Value"
  83.          Height          =   320
  84.          Index           =   0
  85.          Left            =   4000
  86.          TabIndex        =   6
  87.          Top             =   200
  88.          Width           =   1200
  89.       End
  90.       Begin VB.TextBox txtKeyValue 
  91.          Height          =   288
  92.          Left            =   1020
  93.          TabIndex        =   5
  94.          Text            =   "Text1"
  95.          Top             =   1152
  96.          Width           =   2000
  97.       End
  98.       Begin VB.TextBox txtKeyName 
  99.          Height          =   288
  100.          Left            =   1000
  101.          TabIndex        =   4
  102.          Text            =   "Text1"
  103.          Top             =   225
  104.          Width           =   2000
  105.       End
  106.       Begin VB.Label Label1 
  107.          Caption         =   "Key Value :"
  108.          Height          =   192
  109.          Index           =   2
  110.          Left            =   120
  111.          TabIndex        =   3
  112.          Top             =   1200
  113.          Width           =   804
  114.       End
  115.       Begin VB.Label Label1 
  116.          Caption         =   "Key Name :"
  117.          Height          =   192
  118.          Index           =   1
  119.          Left            =   96
  120.          TabIndex        =   2
  121.          Top             =   252
  122.          Width           =   828
  123.       End
  124.    End
  125.    Begin VB.Label Label1 
  126.       Caption         =   "Registry Success :"
  127.       Height          =   192
  128.       Index           =   3
  129.       Left            =   144
  130.       TabIndex        =   15
  131.       Top             =   2280
  132.       Width           =   1332
  133.    End
  134.    Begin VB.Label lblSuccess 
  135.       AutoSize        =   -1  'True
  136.       Caption         =   "_"
  137.       Height          =   195
  138.       Left            =   1635
  139.       TabIndex        =   14
  140.       Top             =   2280
  141.       Width           =   90
  142.    End
  143.    Begin VB.Label Label1 
  144.       Caption         =   "Application Key :"
  145.       Height          =   192
  146.       Index           =   0
  147.       Left            =   120
  148.       TabIndex        =   0
  149.       Top             =   120
  150.       Width           =   1188
  151.    End
  152. End
  153. Attribute VB_Name = "Form1"
  154. Attribute VB_GlobalNameSpace = False
  155. Attribute VB_Creatable = False
  156. Attribute VB_PredeclaredId = True
  157. Attribute VB_Exposed = False
  158. Option Explicit
  159.  
  160. Private Sub cmdExit_Click()
  161.     Unload Me
  162. End Sub
  163.  
  164. Private Sub cmdReg_Click(Index As Integer)
  165. Dim result
  166. Dim KeyResult
  167.     If txtKeyName.Text = "" Then
  168.         ' Warn if no Key Name to create
  169.         MsgBox "KeyName not specified!", vbCritical
  170.         Exit Sub
  171.     End If
  172.     
  173.     If txtKeyValue.Text = "" And (Index = 0 Or Index = 3) Then
  174.         ' Warn if no Value to store. Won't succeed anyway
  175.         result = MsgBox("No Value to store/delete. Proceed Anyway?", vbInformation Or vbYesNo)
  176.         If result = vbNo Then Exit Sub
  177.     End If
  178.     Select Case Index
  179.         Case 0
  180.             ' Creates the key specified in the txtKeyName textbox
  181.             ' and stores the value specified in the txtKeyValue textbox
  182.             If optRegType(0).Value Then
  183.                 ' Stores a REG_DWORD type value
  184.                 result = SetRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text, REG_DWORD, txtKeyValue.Text)
  185.             Else
  186.                 ' Stores a REG_SZ type value
  187.                 result = SetRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text, REG_SZ, txtKeyValue.Text)
  188.             End If
  189.         Case 1
  190.             ' Retrieves the value of the name specified in the
  191.             ' txtKeyName textbox and assign it to the txtKeyValue textbox
  192.             If optRegType(0).Value Then
  193.                 ' Retrieves a REG_DWORD type value
  194.                 result = GetRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text, REG_DWORD, KeyResult)
  195.                 txtKeyValue.Text = regValue 'KeyResult
  196.             Else
  197.                 ' Retrieves a REG_SZ type value
  198.                 result = GetRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text, REG_SZ, KeyResult)
  199.                 txtKeyValue.Text = regValue 'KeyResult
  200.             End If
  201.         Case 2
  202.             ' Delete an entire key. Use with CAUTION when you've change the values
  203.             result = DeleteRegEntry(HKEY_LOCAL_MACHINE, txtAppKeyName.Text)
  204.             txtKeyValue.Text = ""
  205.         Case 3
  206.             ' Delete a key. Use with CAUTION when you've change the values
  207.             result = DeleteRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text)
  208.             txtKeyValue.Text = ""
  209.     End Select
  210.     ' show result in lblSuccess control, either True or False
  211.     If result Then
  212.         lblSuccess.ForeColor = vbBlue
  213.     Else
  214.         lblSuccess.ForeColor = vbRed
  215.     End If
  216.     lblSuccess.Caption = result
  217.     
  218. End Sub
  219.  
  220. Private Sub Form_Load()
  221. Dim result
  222.     txtAppKeyName.Text = regAppKeyName
  223.     lblSuccess.Caption = ""
  224.     
  225.     ' Check if a certain key exist
  226.     ' regAppKeyName = "Software\ECLIPSE Development Software\" & regAppName
  227.     result = regKeyExist(HKEY_LOCAL_MACHINE, regAppKeyName)
  228.     If Not result Then
  229.         ' Creates the key if it doesn't exist.
  230.         ' This key will be deleted when you end this project
  231.         CreateRegEntry HKEY_LOCAL_MACHINE, regAppKeyName
  232.     End If
  233.     
  234.     ' default key to write in the registry.
  235.     ' This can be modified by changing the value
  236.     ' specified in the txtKeyName and txtKeyValue controls.
  237.     txtKeyName.Text = "RegDemo"
  238.     txtKeyValue.Text = "Sample Value to store"
  239. '    result = Val("XXX")
  240. End Sub